﻿using System.Linq;
using System.Web.Mvc;
using Domain;
using System.Data.Entity;
using Web.Models;
using BusinessLogic;
using BusinessLogic.Interfaces;
using Domain.Entities;
using System.Collections.Generic;
using System;
using System.Web.Security;

namespace Web.Controllers
{
    [Authorize]
    public class HomeController : Controller
    {
        private DataManager dataManager;
        public HomeController(DataManager dataManager)
        {
            this.dataManager = dataManager;
        }

        public ActionResult Index()
        {
            ViewData["Dish"] = dataManager.Dishes.GetDishesAll();    
            ViewBag.usname = TempData["UsName"];//TempData до первого прочтения
                ViewBag.uspas = TempData["UsPas"];
                //string UserName = User.Identity.Name;
                string strName = ViewBag.usname;
                string strPas = ViewBag.uspas;
                var us = dataManager.Users.GetUser(strName, strPas);//IEnumerable<User>
                int department_id  = us.Profile.DepartmentID;
                var userProfiles = dataManager.Profiles.GetList(x => x.DepartmentID == department_id);
                ViewBag.Prof = userProfiles;
                ViewBag.Message = DateTime.Now.Hour < 12 ? "Доброе утро, " : "Добрый день, ";
                
                //ViewData["Date"] = DateTime.Now.Date.ToShortDateString();
                return View();//dataManager.Users.GetUsers().ToList() 
        }

        public ActionResult Logout()
        {
            ViewData["Dish"] = dataManager.Dishes.GetDishesAll();
            FormsAuthentication.SignOut(); // завершаем работу
            return RedirectToAction("Index","Account"); // перенаправляем
        }
        
    }

}